package edu.gatech.bsbmule.tests;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.awt.Color;

import org.junit.Before;
import org.junit.Test;

import edu.gatech.bsbmule.model.Store; 
import edu.gatech.bsbmule.model.Player; 


/*
 * This class tests the method sellResource method in the Store Class
 * 
 * It will test the following situations:
 *	-Store sells 3 food
 *	-Store sells 4 energy
 *	-Store sells 2 smithore
 *	-Store sells 1 food mule 
 *
 * @author Vania Xu 
 */

public class JUnit_Vania {
	static Store store; 
	Player player; 
	
	@Before
	public void init() {
		store = Store.getInstance(); 
		player = new Player("Tester", Color.WHITE, Player.RACE_HUMAN, 800, 3,
				3, 3);
	}
	@Test
	public void sellFood() {
		//sells 3 food items 
		int numSold = 3; 
		int expectedPlayerMoney = player.getMoney() 
				- (numSold*store.getPrice(Store.RESOURCE_FOOD));
		int playerExpectedQuant = player.getFood() + numSold; 
		int storeExpectedQuant = store.getItemQuantity(Store.RESOURCE_FOOD) - numSold;
		store.sellResource(player, Store.RESOURCE_FOOD, numSold);
		boolean equals = false; 
		if ((expectedPlayerMoney == player.getMoney()) 
				&& (playerExpectedQuant == player.getFood())
				&& (storeExpectedQuant == store.getItemQuantity(Store.RESOURCE_FOOD)))
			equals = true; 
			
		assertTrue("When the store sells food, it works.", equals); 
	}
	
	
	@Test
	public void sellEnergy() {
		//sells 4 energy
		int numSold = 4; 
		int expectedPlayerMoney = player.getMoney() 
				- (numSold*store.getPrice(Store.RESOURCE_ENERGY));
		int playerExpectedQuant = player.getEnergy() + numSold; 
		int storeExpectedQuant = store.getItemQuantity(Store.RESOURCE_ENERGY) - numSold;
		store.sellResource(player, Store.RESOURCE_ENERGY, numSold);
		boolean equals = false; 
		if ((expectedPlayerMoney == player.getMoney()) 
				&& (playerExpectedQuant == player.getEnergy())
				&& (storeExpectedQuant == store.getItemQuantity(Store.RESOURCE_ENERGY)))
			equals = true; 
			
		assertTrue("When the store sells food, it works.", equals); 
	}
	
	
	@Test
	public void sellSmithore() {
		int numSold = 2; 
		int expectedPlayerMoney = player.getMoney() 
				- (numSold*store.getPrice(Store.RESOURCE_SMITHORE));
		int playerExpectedQuant = player.getSmithore() + numSold; 
		int storeExpectedQuant = store.getItemQuantity(Store.RESOURCE_SMITHORE) - numSold;
		store.sellResource(player, Store.RESOURCE_SMITHORE, numSold);
		boolean equals = false; 
		if ((expectedPlayerMoney == player.getMoney()) 
				&& (playerExpectedQuant == player.getSmithore())
				&& (storeExpectedQuant == store.getItemQuantity(Store.RESOURCE_SMITHORE)))
			equals = true; 
			
		assertTrue("When the store sells food, it works.", equals); 
	}
	
	
	@Test
	public void sellFoodMule() {
		int numSold = 1; 
		int expectedPlayerMoney = player.getMoney() 
				- (numSold*store.getMulePrice(Store.FOOD_MULE));
		player.setMule(Store.FOOD_MULE);
		int playerExpectedMule = player.getMule().getMuleType(); 
		int storeExpectedQuant = store.getItemQuantity(Store.RESOURCE_MULE) - numSold;
		store.sellResource(player, Store.FOOD_MULE, numSold);
		boolean equals = false; 
		if ((expectedPlayerMoney == player.getMoney()) 
				&& (playerExpectedMule == player.getMule().getMuleType())
				&& (storeExpectedQuant == store.getItemQuantity(Store.RESOURCE_MULE)))
			equals = true; 
			
		assertTrue("When the store sells food, it works.", equals); 
	}
}
